package cn.seocoo.platform.web.controller.user;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.user.domain.AppUser;
import cn.seocoo.platform.user.service.IAppUserService;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;

/**
 * APP注册用户 信息操作处理
 * 
 * @author wujian
 * @date 2019-12-20
 */
@Controller
@RequestMapping("/user/appUser")
public class AppUserController extends BaseController
{
    private String prefix = "user/user";
	
	@Autowired
	private IAppUserService appUserService;
	
	@RequiresPermissions("user:user:view")
	@GetMapping()
	public String appUser()
	{
	    return prefix + "/user";
	}
	
	/**
	 * 查询APP注册用户列表
	 */
	@RequiresPermissions("user:user:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AppUser appUser)
	{
		startPage();
        List<AppUser> list = appUserService.selectAppUserList(appUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出APP注册用户列表
	 */
	@RequiresPermissions("user:user:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppUser appUser)
    {
    	List<AppUser> list = appUserService.selectAppUserList(appUser);
        ExcelUtil<AppUser> util = new ExcelUtil<AppUser>(AppUser.class);
        return util.exportExcel(list, "user");
    }
	
	/**
	 * 新增APP注册用户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存APP注册用户
	 */
	@RequiresPermissions("user:user:add")
	@Log(title = "APP注册用户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AppUser appUser)
	{		
		return toAjax(appUserService.insertAppUser(appUser));
	}

	/**
	 * 修改APP注册用户
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		AppUser appUser = appUserService.selectAppUserById(id);
		mmap.put("user", appUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存APP注册用户
	 */
	@RequiresPermissions("user:user:edit")
	@Log(title = "APP注册用户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AppUser appUser)
	{		
		return toAjax(appUserService.updateAppUser(appUser));
	}
	
	/**
	 * 删除APP注册用户
	 */
	@RequiresPermissions("user:user:remove")
	@Log(title = "APP注册用户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(appUserService.deleteAppUserByIds(ids));
	}
	
}
